package com.seteam.collabcrossword;

import com.seteam.collabcrossword.exceptions.CollabCrosswordException;
import com.seteam.collabcrossword.exceptions.CoordinatesException;
import com.seteam.collabcrossword.exceptions.TileException;

/**
 * This class provides static utility methods to reduce code redundancy
 * in other classes
 */
public class CollabCrosswordUtils {
    /**
     * Checks if the given integer is positive. Throws an exception if it's not
     *
     * @param theIntValue the integer to be checked
     * @param message     message in case an exception occurs
     * @throws CollabCrosswordException if the value of the integer is negative
     */
    public static void isPositive(final int theIntValue, final String message) throws CollabCrosswordException {
        if (theIntValue < 0) {
            throw new CollabCrosswordException(message);
        }
    }

    /**
     * Checks if the given instance of {@link Tile} is null
     *
     * @param tile    the instance to be checked
     * @param message message in case an exception occurs
     * @throws TileException if the instance passed is null
     */
    public static void checkNotNull(final Tile tile, final String message) throws TileException {
        if (tile == null) {
            throw new TileException(message);
        }
    }

    /**
     * Checks if the given string is null or empty
     *
     * @param theString the string to be checked
     * @param message   message in case an exception occurs
     * @throws CollabCrosswordException if the string is null or empty
     */
    public static void checkNotNull(final String theString, final String message) throws CollabCrosswordException {
        if (theString == null || theString.length() == 0) {
            throw new CollabCrosswordException(message);
        }
    }

    /**
     * Checks if the given instance of {@link Coordinates} is null
     *
     * @param coordinates the instance to be checked
     * @param message     message in case an exception occurs
     * @throws CoordinatesException if the instance passed is null
     */
    public static void checkNotNull(final Coordinates coordinates, final String message) throws CoordinatesException {
        if (coordinates == null) {
            throw new CoordinatesException(message);
        }
    }
}
